import type { DefaultTheme } from 'vitepress'
import fs from 'fs-extra'

// 读取日常笔记配置
const sidebarDailyNotes: DefaultTheme.SidebarItem[] =
  fs.readJSONSync('./scripts/daily-notes.json', { throws: false }) || []

// 侧边栏配置 - 针对Java后端开发
export const sidebar: DefaultTheme.Config['sidebar'] = {
  // Java基础知识
  '/java/': [
    {
      text: 'Java核心语法',
      collapsed: false,
      items: [
        { text: '数据类型', link: '/java/basic/syntax' },
        { text: '运算符与控制流', link: '/java/basic/control' },
        { text: '异常处理', link: '/java/basic/exception' }
      ]
    },
    {
      text: '面向对象',
      collapsed: false,
      items: [
        { text: '类与对象', link: '/java/basic/oop' },
        { text: '继承与多态', link: '/java/basic/inheritance' },
        { text: '接口与抽象类', link: '/java/basic/interface' }
      ]
    },
    {
      text: '集合框架',
      collapsed: false,
      items: [
        { text: 'List集合', link: '/java/basic/collection' },
        { text: 'Set集合', link: '/java/basic/set' },
        { text: 'Map集合', link: '/java/basic/map' }
      ]
    },
    {
      text: 'IO流',
      collapsed: false,
      items: [
        { text: '字节流与字符流', link: '/java/basic/io' },
        { text: 'NIO', link: '/java/basic/nio' }
      ]
    },
    {
      text: '并发编程',
      link: '/java/concurrent/',
      collapsed: false,
      items: [
        { text: '线程基础', link: '/java/concurrent/thread' },
        { text: '线程池', link: '/java/concurrent/threadpool' },
        { text: '锁机制', link: '/java/concurrent/lock' }
      ]
    },
    {
      text: 'JVM原理',
      link: '/java/jvm/',
      collapsed: false,
      items: [
        { text: '内存模型', link: '/java/jvm/memory' },
        { text: '垃圾回收', link: '/java/jvm/gc' },
        { text: '类加载机制', link: '/java/jvm/classloader' }
      ]
    }
  ],
  // 主流框架
  '/framework/': [
    {
      text: 'Spring Framework',
      link: '/framework/spring/',
      collapsed: false,
      items: [
        { text: 'IoC容器', link: '/framework/spring/ioc' },
        { text: 'AOP面向切面', link: '/framework/spring/aop' },
        { text: '事务管理', link: '/framework/spring/transaction' }
      ]
    },
    {
      text: 'Spring Boot',
      link: '/framework/springboot/',
      collapsed: false,
      items: [
        { text: '自动配置原理', link: '/framework/springboot/auto-config' },
        { text: 'Starter机制', link: '/framework/springboot/starter' },
        { text: '常用注解', link: '/framework/springboot/annotations' }
      ]
    },
    {
      text: 'Spring Cloud',
      link: '/framework/springcloud/',
      collapsed: false,
      items: [
        { text: '微服务概念', link: '/framework/springcloud/concept' },
        { text: '服务注册', link: '/framework/springcloud/registry' }
      ]
    },
    {
      text: 'MyBatis',
      link: '/framework/mybatis/',
      collapsed: false,
      items: [
        { text: '基本使用', link: '/framework/mybatis/basic' },
        { text: '动态SQL', link: '/framework/mybatis/dynamic-sql' },
        { text: '缓存机制', link: '/framework/mybatis/cache' }
      ]
    }
  ],
  // 数据库
  '/database/': [
    {
      text: 'MySQL',
      link: '/database/mysql/',
      collapsed: false,
      items: [
        { text: 'SQL基础', link: '/database/mysql/sql' },
        { text: '索引优化', link: '/database/mysql/index' },
        { text: '事务与锁', link: '/database/mysql/transaction' }
      ]
    },
    {
      text: 'Redis',
      link: '/database/redis/',
      collapsed: false,
      items: [
        { text: '数据类型', link: '/database/redis/datatype' },
        { text: '持久化', link: '/database/redis/persistence' },
        { text: '缓存策略', link: '/database/redis/cache' }
      ]
    },
    {
      text: 'MongoDB',
      link: '/database/mongodb/',
      collapsed: false,
      items: [
        { text: '基本操作', link: '/database/mongodb/basic' },
        { text: '聚合操作', link: '/database/mongodb/aggregation' }
      ]
    }
  ],
  // 微服务
  '/microservice/': [
    {
      text: '服务注册与发现',
      link: '/microservice/registry/',
      collapsed: false,
      items: [
        { text: 'Nacos', link: '/microservice/registry/nacos' },
        { text: 'Eureka', link: '/microservice/registry/eureka' }
      ]
    },
    {
      text: '配置中心',
      link: '/microservice/config/',
      collapsed: false,
      items: [
        { text: 'Nacos Config', link: '/microservice/config/nacos' },
        { text: 'Apollo', link: '/microservice/config/apollo' }
      ]
    },
    {
      text: '网关',
      link: '/microservice/gateway/',
      collapsed: false,
      items: [
        { text: 'Spring Cloud Gateway', link: '/microservice/gateway/scg' },
        { text: '路由配置', link: '/microservice/gateway/route' }
      ]
    }
  ],
  // 消息队列
  '/mq/': [
    {
      text: 'RabbitMQ',
      link: '/mq/rabbitmq/',
      collapsed: false,
      items: [
        { text: '基本概念', link: '/mq/rabbitmq/basic' },
        { text: '工作模式', link: '/mq/rabbitmq/mode' }
      ]
    },
    {
      text: 'Kafka',
      link: '/mq/kafka/',
      collapsed: false,
      items: [
        { text: '基础概念', link: '/mq/kafka/basic' },
        { text: '生产者与消费者', link: '/mq/kafka/producer-consumer' }
      ]
    }
  ],
  // 源码阅读
  '/analysis/': [
    {
      text: 'Spring源码',
      items: [
        { text: 'IoC容器源码', link: '/analysis/spring/ioc' },
        { text: 'AOP源码', link: '/analysis/spring/aop' }
      ]
    },
    {
      text: 'MyBatis源码',
      items: [
        { text: '执行流程', link: '/analysis/mybatis/flow' },
        { text: '插件机制', link: '/analysis/mybatis/plugin' }
      ]
    },
    {
      text: 'JDK源码',
      items: [
        { text: 'HashMap源码', link: '/analysis/jdk/hashmap' },
        { text: 'ConcurrentHashMap源码', link: '/analysis/jdk/concurrenthashmap' }
      ]
    }
  ],
  // 开发工具
  '/tools/': [
    {
      text: 'IDEA技巧',
      link: '/tools/idea/',
      collapsed: false,
      items: [
        { text: '快捷键', link: '/tools/idea/shortcuts' },
        { text: '插件推荐', link: '/tools/idea/plugins' }
      ]
    },
    {
      text: 'Maven/Gradle',
      link: '/tools/build/',
      collapsed: false,
      items: [
        { text: 'Maven使用', link: '/tools/build/maven' },
        { text: 'Gradle使用', link: '/tools/build/gradle' }
      ]
    },
    {
      text: 'Git使用',
      link: '/tools/git/',
      collapsed: false,
      items: [
        { text: 'Git基本命令', link: '/tools/git/basic' },
        { text: 'Git高级技巧', link: '/tools/git/advanced' }
      ]
    },
    {
      text: 'Linux命令',
      link: '/tools/linux/',
      collapsed: false,
      items: [
        { text: '常用命令', link: '/tools/linux/commands' },
        { text: 'Shell脚本', link: '/tools/linux/shell' }
      ]
    },
    {
      text: 'Docker',
      link: '/tools/docker/',
      collapsed: false,
      items: [
        { text: 'Docker基础', link: '/tools/docker/basic' },
        { text: 'Docker Compose', link: '/tools/docker/compose' }
      ]
    }
  ],
  // 提效工具
  '/efficiency/': [
    {
      text: '软件推荐与配置',
      items: [
        { text: '多平台软件', link: '/efficiency/software/cross-platform' },
        { text: 'Mac 平台', link: '/efficiency/software/mac' },
        { text: 'Windows 平台', link: '/efficiency/software/windows' },
        { text: '浏览器设置与扩展', link: '/efficiency/software/browser' },
        { text: 'IntelliJ IDEA 配置', link: '/efficiency/software/idea' }
      ]
    },
    { text: '在线工具', link: '/efficiency/online-tools' },
    { text: '书签脚本', link: '/efficiency/bookmark-scripts' }
  ],
  // 踩坑记录
  '/pit/': [
    {
      text: '踩坑记录',
      items: [
        { text: 'Spring踩坑', link: '/pit/spring' },
        { text: 'MyBatis踩坑', link: '/pit/mybatis' },
        { text: '数据库踩坑', link: '/pit/database' },
        { text: '微服务踩坑', link: '/pit/microservice' },
        { text: '部署踩坑', link: '/pit/deploy' }
      ]
    }
  ],
  // 日常笔记
  '/daily-notes': sidebarDailyNotes
}
